<?php
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
/*===================================================================
= Query Builder File for the Treeview Management
= Duleepa Wijayawardhana 29.07.2003
=====================================================================*/


switch ($_REQUEST["action"])
{
	//------------------ADD CHANNEL ------------------------------------------------------------------------------//
	case "addEntry":
		//Are the correct pieces of information here
		if ($_POST["name"]!="")
		{
			$name=htmlspecialchars(strip_tags($_POST["name"]));
			
			if (is_array($_POST["roleID"]))
			{
				$sRoleStr=implode(":", $_POST["roleID"]);
			}
			
			
			$sql="INSERT INTO treeEntry SET
				name='".$name."',
				link='".$_POST["link"]."',
				parentID='".$_POST["parentID"]."',
				roleID='".$sRoleStr."'";
			$insert=db_query($sql);

			//Send them to the view tree page?
			header("Location: index.html");
			exit;
		}
		break;
		case "deleteEntry":
		//Are the correct pieces of information here
		if ($_REQUEST["entryID"]>0)
		{
			$sql="SELECT parentID FROM treeEntry WHERE ID=".$_REQUEST["entryID"];
			$parentInfo=mysql_fetch_array(run_mysql_query($sql));
			
			$sql="UPDATE treeEntry SET parentID=".$parentInfo["parentID"]." WHERE parentID=".$_REQUEST["entryID"];
			$result=run_mysql_query($sql);
			
			$sql="DELETE FROM treeEntry WHERE ID=".$_REQUEST["entryID"];
			$result=run_mysql_query($sql);
			
			//Send them to the view tree page?
			header("Location: index.html");
			exit;
		}
		break;
		case "editEntry":
		//Are the correct pieces of information here
		if ($_POST["name"]!="" && $_POST["entryID"]>0)
		{
			$name=htmlspecialchars(strip_tags($_POST["name"]));
			
			if (is_array($_POST["roleID"]))
			{
				$sRoleStr=implode(":", $_POST["roleID"]);
			}
			
			
			$sql="UPDATE treeEntry SET
				name='".$name."',
				link='".$_POST["link"]."',
				roleID='".$sRoleStr."'
				WHERE ID=".$_POST["entryID"];
			$insert=db_query($sql);

			//Send them to the view tree page?
			header("Location: index.html");
			exit;
		}
		break;
		case "orderChildren":
			//Are the correct pieces of information here
			if (is_array($_POST["catlist"]))
			{
				for ($i=0; $i<count($_POST["catlist"]); $i++)
				{
					$sql="UPDATE treeEntry SET ord='".$i."' WHERE ID='".$_POST["catlist"][$i]."'";
					$update=run_mysql_query($sql);
				}
				
				header("Location: index.html");
				exit;
				
			}
			break;
	
}

header("Location: index.html");
exit;
?>
